package com.wt.admin.controller.chat;


import com.aizuda.easy.security.domain.Rep;
import com.aizuda.easy.security.domain.Req;
import com.wt.admin.domain.dto.chat.ChatDTO;
import com.wt.admin.domain.dto.chat.ChatModelContentDTO;
import com.wt.admin.domain.dto.chat.ChatModelDTO;
import com.wt.admin.domain.dto.chat.ChatModelFileDTO;
import com.wt.admin.domain.vo.chart.*;
import com.wt.admin.domain.vo.sys.UserVO;
import com.wt.admin.service.chart.ChatProxyService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

import java.util.List;


@RestController
@RequestMapping("chat")
public class ChatController {

    @Resource
    private ChatProxyService chatProxyService;


    @PostMapping("modelEdit")
    public Rep<ChatModelVO> modelEdit(@RequestBody Req<ChatModelDTO, UserVO> req) {
        return Rep.ok(chatProxyService.getChatModelService().modelEdit(req.getData()));
    }

    @PostMapping("modeList")
    public Rep<ChatModeListVO> modeList(@RequestBody Req<ChatModelDTO, UserVO> req) {
        return Rep.ok(chatProxyService.modeList(req.getData()));
    }

    @PostMapping("modeDel")
    public Rep<List<ChatModelVO>> modeDel(@RequestBody Req<ChatModelDTO, UserVO> req) {
        return Rep.ok(chatProxyService.modeDel(req.getData()));
    }

    @PostMapping("modeFileList")
    public Rep<List<ChatModelFileVO>> modeFileList(@RequestBody Req<ChatModelFileDTO, UserVO> req) {
        return Rep.ok(chatProxyService.getChatModelFileService().modeFileList(req.getData()));
    }

    @PostMapping("modeFileDel")
    public Rep<ChatModelFileVO> modeFileDel(@RequestBody Req<List<String>, UserVO> req) {
        return Rep.ok(chatProxyService.modeFileDel(req.getData()));
    }

    @PostMapping("modeContentList")
    public Rep<List<ChatModelContentVO>> modeContentList(@RequestBody Req<ChatModelContentDTO, UserVO> req) {
        return Rep.ok(chatProxyService.getChatModelContentService().modeContentList(req.getData(), req.getUser()));
    }

    @PostMapping("modeContentDel")
    public Rep<ChatModelContentVO> modeContentDel(@RequestBody Req<ChatModelContentDTO, UserVO> req) {
        return Rep.ok(chatProxyService.modeContentDel(req.getData()));
    }

    @PostMapping("modeContentEdit")
    public Rep<ChatModelContentVO> modeContentEdit(@RequestBody Req<ChatDTO, UserVO> req) {
        return Rep.ok(chatProxyService.modeContentEdit(req.getData(), req.getUser()));
    }

    @PostMapping("modeContentInfo")
    public Rep<ChatModelContentVO> modeContentInfo(@RequestBody Req<ChatModelContentDTO, UserVO> req) {
        return Rep.ok(chatProxyService.modeContentInfo(req.getData(), req.getUser()));
    }

    @PostMapping("question")
    public Flux<String> question(@RequestBody Req<ChatDTO, UserVO> req) {
        final StringBuilder msg = new StringBuilder();
        return chatProxyService.question(req.getData(), req.getUser())
                .stream()
                .content()
                .doOnNext(msg::append)
                .doOnError(error -> msg.setLength(0))
                .doOnComplete(() -> chatProxyService.reply(msg.toString(),req.getData(),req.getUser()));
    }


}
